const {joinRootDir}= require("../util.js")
const api= require("./api/index.js")

module.exports = function (app,static) {
    app.use((req, res, next) => {
        res.header('Access-Control-Allow-Origin', '*')
        res.header('Access-Control-Allow-Headers', 'Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method' )
        res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PATCH, PUT, DELETE')
        res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE')
        next()
    })
    
    // 公共静态资源目录
    app.use('/public', static(joinRootDir("public")))  

    // 公共接口
    app.use('/api', api)
    

    // 各种学习和测试功能
    app.use('/testStatic', static(joinRootDir("test")))
    
    
    // 前端打包项目
    app.use('/webindex', static(joinRootDir("htmlProject/webindex/build")))
    app.use('/chatRoom', static(joinRootDir("htmlProject/chatRoom/build")))
    app.use('/resume', static(joinRootDir("htmlProject/resume/build")))
}
